<?php

class Usuario extends AppModel {

    var $name = 'Usuario';
    var $displayField = 'nome';
    var $dependent = true;
    //The Associations below have been created with all possible keys, those that are not needed can be removed

    var $hasMany = array(
        'PerfilAcesso' => array(
            'className' => 'PerfilAcesso',
            'foreignKey' => 'usuario_id',
            'dependent' => true,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );

    /**
     * Utilizado para formatar a data do último_acesso no padrao brasil
     */
    function afterFind($results) {

        if ($results) {

            foreach ($results as $key => $val) {

                if (isset($val['Usuario']['ultimo_acesso'])) {
                    $data = explode(' ', $val['Usuario']['ultimo_acesso']);
                    $results[$key]['Usuario']['ultimo_acesso'] = $this->dateFormate($data[0]) . ' ' . $data[1];
                }
            }
        }
        return $results;
    }

}
